import axios from 'axios'
import { merge } from 'lodash'
import { GRAPH_PREFIX } from '@/components/storybook/settings/graphSetting'

export const msalConfig = {
  graphMeEndpoint: `${GRAPH_PREFIX}/v1.0/me`
}

export function callMSGraph(endpoint, token, config) {
  const options = {
    headers: {
      Authorization: `Bearer ${token}`
    }
  }

  return axios.get(endpoint, merge({}, options, config))
}

export function useGraph() {
  const getMe = token => {
    return callMSGraph(msalConfig.graphMeEndpoint, token)
  }

  return {
    getMe
  }
}
